package com.tyson.controller;


import com.tyson.entity.Fruit;
import com.tyson.service.FruitService;
import com.tyson.vo.BarVO;
import com.tyson.vo.PieVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author admin
 * @since 2021-04-11
 */
@RestController
@RequestMapping("/fruit")


public class FruitController {
    @Autowired
    private FruitService fruitService;

    @GetMapping("/list")
    public List<Fruit> list() {
        return this.fruitService.list();
    }


    @DeleteMapping("/delete/{id}")
    public boolean delete(@PathVariable("id") Integer id) {
        return this.fruitService.removeById(id);

    }

    @GetMapping("find/{id}")
    public Fruit findById(@PathVariable("id") Integer id) {
        return this.fruitService.getById(id);
    }

    @PutMapping("update")
    public boolean updateById(@RequestBody Fruit fruit) {
        return this.fruitService.updateById(fruit);
    }


    @PostMapping("/add")
    public boolean add(@RequestBody Fruit fruit){
        return  this.fruitService.save(fruit);
    }

    @GetMapping("/barVO")
    public BarVO barV(){
        return this.fruitService.barVOList();
    }
    @GetMapping("/pieVO")
    public List<PieVO> pieVO(){
        return this.fruitService.pieVOList();
    }
}

